package lesson.tcs;

import lesson.db.DbUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class TeacherClassSubjectService {





    /**
     * 添加
     * @param tcs
     * @return
     */
    public String add(TeacherClassSubject tcs) {
        String result = null;
        SqlSession session = DbUtil.getSession(true);
        try{
            TeacherClassSubjectDao dao = session.getMapper(TeacherClassSubjectDao.class);
            boolean exist = dao.checkExist(tcs);
            if (exist) {
                result = "该班级学科已被分配过";
            } else {
                dao.add(tcs);
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {

            session.close();
        }


        return result;
    }


    /**
     * 删除
     * @param id
     * @return
     */
    public String del(Integer id) {
        SqlSession session = DbUtil.getSession(true);
        try{
            TeacherClassSubjectDao dao = session.getMapper(TeacherClassSubjectDao.class);
            dao.del(id);

        }catch (Exception e){
            e.printStackTrace();

        }finally {

            session.close();
        }


        return null;
    }

    public List<TeacherClassSubject> list(Integer teacherId) {
        SqlSession session = DbUtil.getSession(true);
        TeacherClassSubjectDao dao = session.getMapper(TeacherClassSubjectDao.class);
        List<TeacherClassSubject> list = dao.list(teacherId);
        session.close();
        return list;
    }
}
